package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.model.product.SkuInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

// @Controller
public class HelloController {

    // ThymeleafTest
    @GetMapping(value = {"/hello", "/trade.html"})
    public String hello(Map map, HttpSession session, HttpServletRequest request) {

        map.put("hello", "世界你好");

        SkuInfo skuInfo = new SkuInfo();
        skuInfo.setId(24L);
        map.put("skuInfo", skuInfo);

        List<SkuInfo> skuInfoList = new ArrayList<>();
        SkuInfo skuInfo1 = new SkuInfo();
        skuInfo1.setId(123L);
        SkuInfo skuInfo2 = new SkuInfo();
        skuInfo2.setId(456L);
        skuInfoList.add(skuInfo1);
        skuInfoList.add(skuInfo2);
        map.put("skuInfoList", skuInfoList);

        session.setAttribute("hello", "SessionData");

        request.setAttribute("gname", "<span style=\"color:green\">宝强</span>");

        return "helloThymeleaf";
    }
}
